(*
   Copyright (c) 2023-2025 Semgrep Inc.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public License
   version 2.1 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
   LICENSE for more details.
*)
(* This module allows the generation of fresh types for unique identifiers.
   Such identifiers generated by `mk` are guaranteed to be distinct from each
   other.*)
module MkId () : sig
  (* abstract type! *)
  type t [@@deriving show, eq, ord, hash, sexp]

  val mk : unit -> t
  val to_int : t -> int

  (* `unsafe_default` is distinct from all generated IDs, but not from other
     `unsafe_default`s.
  *)
  val unsafe_default : t
  val is_unsafe_default : t -> bool

  type partition = A | B

  (* Defaults to partition A. IDs generated from different partitions are
   * guaranteed to be distinct from each other even across different runs of the
   * binary.
   *
   * This is useful if we want to serialize a data structure that includes IDs,
   * then deserialize it in a different run for use alongside fresh IDs. Using
   * one partition when constructing the serialized data, and another for a
   * normal run ensures that we will avoid collisions.
   *)
  val set_partition : partition -> unit
end
